<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="zh-CN">
<head>
<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
			<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
			<title>用户管理</title> <!-- Bootstrap -->
			<link href="/SmartCommunity/css/pc/bootstrap.css" rel="stylesheet">
				<link href="/SmartCommunity/css/pc/main.css" rel="stylesheet">
						
</head>
<body>
	<nav class="navbar navbar-inverse navbar-fixed-top">
	<div class="container">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle collapsed"
				data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
				aria-expanded="false">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="navbar-brand  smart active" href="/SmartCommunity/views/pc/smart.html">SMART</a>
		</div>
		<!-- Collect the nav links, forms, and other content for toggling -->
		<div class="collapse navbar-collapse"
			id="bs-example-navbar-collapse-1">
			<ul class="nav navbar-nav">
			</ul>
			<form class="navbar-form navbar-right">
				<a class="btn btn-primary" id="quit">退出</a>
			</form>
		</div>
	</div>
	</nav>

	<div class="col-md-2"></div>
	<div class="maincontentinner col-md-8">
		<h4 class="widgettitle">用户管理表</h4>
		<div class="dataTables_filter">
			<input type="text" id="search_text" class="user_search" /> <input
				type="button" value="搜索" id="search_btn" />
			<div class="add_btn">
				<label>添加：</label> <a href="javascript:void(0);"
					onclick="add(this);"><span class="glyphicon glyphicon-plus"
					aria-hidden="true"></a></span>
			</div>
		</div>
		<table class="table table-bordered responsive">
			<thead>
				<tr>
					<th class="center">姓名</th>
					<th class="center">手机</th>
					<th class="center">权限</th>
					<th class="center">修改</th>
					<th class="center">删除</th>
				</tr>
			</thead>
			<tbody id="table_body">
				<tr class="template-user" style="display: none">
					<td class="name center"></td>
					<td class="phone center"></td>
					<td class="type center"></td>
					<td class="modify center"><a href="javascript:void(0);"
						onclick="modify(this);"><span class="glyphicon glyphicon-pencil"
							aria-hidden="true"></a></span></td>
					<td class="center"><a href="javascript:void(0);"
						onclick="delete_add(this);"><span
							class="glyphicon glyphicon-trash" aria-hidden="true"></a></span></td>
				</tr>

			</tbody>
		</table>
		<div id="page1" class="page_foot"></div>
	</div>

	<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog"
		aria-labelledby="exampleModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="exampleModalLabel">修改用户信息</h4>
				</div>
				<div class="modal-body">
					<form>
						<div class="form-group">
							<label for="modify_name" class="control-label">姓名</label> <input
								type="text" class="form-control" id="modify_name">
						</div>
						<div class="form-group">
							<label for="modify_phone" class="control-label">手机号</label> <input
								type="text" class="form-control" id="modify_phone">
						</div>
						<div class="form-group">
							<label for="modify_password" class="control-label">密码</label> <input
								type="text" class="form-control" id="modify_password">
						</div>
						<div class="form-group">
							<label for="modify_type" class="control-label">权限</label> <select
								class="form-control" id="modify_type">
								<option value="0">物业管理人员</option>
								<option value="1">快递录入人员</option>
							</select>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" id="btn_sure" class="btn btn-primary"
						onclick="submitOK(this)">提交</button>
				</div>
			</div>
		</div>
	</div>

	<div class="modal fade" id="exampleModalAdd" tabindex="-1"
		role="dialog" aria-labelledby="exampleModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="exampleModalLabelAdd">添加用户信息</h4>
				</div>
				<div class="modal-body">
					<form>
						<div class="form-group">
							<span class="imp">*</span><label for="add_name" class="control-label">姓名</label>&nbsp;&nbsp;<span class="imp error_name" style="display:none;">请输入用户名字</span> <input
								type="text" class="form-control" id="add_name">
						</div>
						<div class="form-group">
							<span class="imp">*</span><label for="add_phone" class="control-label">手机号</label>&nbsp;&nbsp;<span class="imp error_phone" style="display:none;">请输入用户手机号</span> <input
								type="text" class="form-control" id="add_phone">
						</div>
						<div class="form-group">
							<span class="imp">*</span><label for="add_password" class="control-label">密码</label>&nbsp;&nbsp;<span class="imp error_password" style="display:none;">请输入密码</span> <input
								type="text" class="form-control" id="add_password">
						</div>
						<div class="form-group">
							<span class="imp">*</span><label for="add_type" class="control-label">权限</label>&nbsp;&nbsp;<span class="imp error_type" style="display:none;">请输入选择用户权限</span> <select
								class="form-control" id="add_type">
								<option value="">请选择</option>
								<option value="0">物业管理人员</option>
								<option value="1">快递录入人员</option>
							</select>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" id="btn_sure_add" class="btn btn-primary"
						onclick="submitOKAdd(this)">提交</button>
				</div>
			</div>
		</div>
	</div>
	<script src="/SmartCommunity/js/pc/jquery.js"></script>
	<script src="/SmartCommunity/js/pc/init.js"></script>
	<script src="/SmartCommunity/js/pc/page.js"></script>
	<!-- Include all compiled plugins (below), or include individual files as needed -->
	<script src="/SmartCommunity/js/pc/bootstrap.js"></script>
	 <script src="/SmartCommunity/js/pc/jquery.atmosphere.js"></script>
	<script>
		init();
		//var arr_G;
		var page_num=1;
		ajax_trans("/SmartCommunity/pc/get_admin_list?page="+page_num);
	function ajax_trans(url_http){
			$.ajax({
				type: "POST",
				url: url_http,
				contentType: "application/json;charset=utf-8",
				success: function(data){
					//alert("success method");
					//alert(data);
					var arr=eval("("+data+")");
					//alert(arr);
					//var arr=data;
					var pages = Math.ceil(parseInt(arr.count)/10);
					$("#page1").unbind();
					count_pages(pages);
					arr1=arr.content;
					for(var i =0; i <arr1.length; i++){
				    	var row = $(".template-user").eq(0).clone();
						row.find(".name").text(arr1[i].adminName);
						row.find(".phone").text(arr1[i].telephoneNum);
						//row.find(".password").text(arr1[i].password);
						if(arr1[i].type=="1"){
							sel="快递录入人员";
						}
						else{
							sel="物业管理人员";
						}
						row.find(".type").text(sel);
						row.attr("id",arr1[i].id);
						if(i==0){
							document.getElementById("table_body").innerHTML="";
						}
						row.css("display", "table-row");
						row.appendTo("#table_body");   
				    }
				},
				error: function(data){
					alert("error");	
				} 
				});
		}
	function ajax_trans_page(url_http){
		$.ajax({
			type: "POST",
			url: url_http,
			contentType: "application/json;charset=utf-8",
			success: function(data){
				//alert("success method");
				//alert(data);
				var arr=eval("("+data+")");
				//alert(arr);
				//var arr=data;
				arr1=arr.content;
				for(var i =0; i <arr1.length; i++){
			    	var row = $(".template-user").eq(0).clone();
					row.find(".name").text(arr1[i].adminName);
					row.find(".phone").text(arr1[i].telephoneNum);
					//row.find(".password").text(arr1[i].password);
					if(arr1[i].type=="1"){
						sel="快递录入人员";
					}
					else{
						sel="物业管理人员";
					}
					row.find(".type").text(sel);
					row.attr("id",arr1[i].id);
					if(i==0){
						document.getElementById("table_body").innerHTML="";
					}
					row.css("display", "table-row");
					row.appendTo("#table_body");   
			    }
			},
			error: function(data){
				alert("error");	
			} 
			});
	}
function count_pages(num){
	//alert("a");
	 $("#page1").createPage({
	        pageCount:num,
	        current:page_num,
	        backFn:function(p){
	        	alert(p);
	        	page_num=p;
	        	ajax_trans_page("/SmartCommunity/pc/get_admin_list?page="+p);
	        }		
	    });	
}	

		$("#search_btn").click(function(){
			var text1=$("#search_text").val();
			//if(text1==""){
				//alert("请输入搜索内容");
				//return false;
			//}
			$.ajax({
				type:"POST",
				url:"/SmartCommunity/pc/search_admin",
				//contentType:"application/json;charset=utf-8",
				data:{search:text1},
				success:function(data){
					//alert("search success method ");
					var arr=eval("("+data+")");
					//alert(arr.count);
					if(arr.count!=0)
					{
						//alert("搜索到相关内容");
						page_num=1;
						var pages = Math.ceil(parseInt(arr.count)/10);
						$("#page1").unbind();
						count_pages(pages);
						arr1=arr.content;
						//alert("arr1:"+arr1);
						//alert(arr1.length);
						for(var i =0; i <arr1.length; i++){
					    	var row = $(".template-user").eq(0).clone();
							row.find(".name").text(arr1[i].adminName);
							row.find(".phone").text(arr1[i].telephoneNum);
							//row.find(".password").text(arr1[i].password);
							if(arr1[i].type=="1"){
								sel="快递录入人员";
							}
							else{
								sel="物业管理人员";
							}
							row.find(".type").text(sel);
							row.attr("id",arr1[i].id);
							if(i==0){
								document.getElementById("table_body").innerHTML="";
							}
							row.css("display", "table-row");
							row.appendTo("#table_body");   
					    }
					}
					else
					{
						alert("未搜索到相关内容");
					}
				},
				error:function(){
					alert("error");
				}
			});
			
		});
		function modify(obj){
			var par=$(obj).parent().parent();
			var temp=par.attr("id");
			//alert(temp);
			var tds=par.find('td');
	    	$('#modify_name').val(tds.eq(0).text());
			$('#modify_phone').val(tds.eq(1).text()); 
			//$('#modify_password').val(tds.eq(2).text());
			if(tds.eq(3).text()=="快递录入人员"){
				sel="1";
			}
			else{
				sel="0";
			}
			$("#modify_type").val(sel);
			$("#btn_sure").addClass(temp);
			$('#exampleModal').modal('show');
		}
		function submitOK(e){
			var id1=$(e).attr("class");
			var group=id1.split(" ");
			var a=$("#"+group[2]).index();
			var modify_name=$('#modify_name').val();
			var modify_phone= $('#modify_phone').val(); 
			var modify_password=$('#modify_password').val();
			var modify_type=$("#modify_type").val();
			$.ajax({
				type:"POST",
				url:"/SmartCommunity/pc/update_admin",
				contentTpye:"application/json;charset=utf-8",
				data:{adminName:modify_name,telephoneNum:modify_phone,password:modify_password,type:modify_type,id:group[2]},
				success:function(data)
				{
					//alert("modify success method");
					//alert(data);
					if(data=="true"){
						alert("修改成功");
						ajax_trans_page("/SmartCommunity/pc/get_admin_list?page="+page_num);
					}
					else{
						alert("修改失败！");
					}
				},
				error:function(data)
				{
					//var arr=eval(data);
					//alert(arr);
					alert("error");
				}
			});
			
		}
		function add(){
			$('#exampleModalAdd').modal('show');
		}
		function submitOKAdd(e){
			var add_name=$('#add_name').val();
			var add_phone= $('#add_phone').val(); 
			var add_password=$('#add_password').val();
			var add_type=$("#add_type").val();
			if(add_name==""){
				$(".error_name").show();
				$('#add_name').focus();
				return false;
			}
			$(".error_name").hide();
			if(add_phone==""){
				$(".error_phone").show();
				$('#add_phone').focus();
				return false;
			}
			$(".error_phone").hide();
			if(add_password==""){
				$(".error_password").show();
				$('#add_password').focus();
				return false;
			}
			$(".error_password").hide();
			if(add_type==""){
				$(".error_type").show();
				return false;
			}
			$(".error_type").hide();
			$.ajax({
				type:"POST",
				url:"/SmartCommunity/pc/add_admin",
				contentTpye:"application/json;charset=utf-8",
				data:{adminName:add_name,telephoneNum:add_phone,password:add_password,type:add_type},
				success:function(data){
					if(data=="true"){
						alert("添加成功");
						ajax_trans_page("/SmartCommunity/pc/get_admin_list?page="+page_num);
					}
					else{
						alert("添加失败！");
					}
				},
				error:function(){
					alert("error");
				}
			});
			
		}
		function delete_add(e){
			var par=$(e).parent().parent();
			var id_d=par.attr("id");
			var temp=par.index();
			if (confirm("你确定删除吗？")) { 
				$.ajax({
					type:"POST",
					url:"/SmartCommunity/pc/delete_admin",
					contentTpye:"application/json;charset=utf-8",
					data:{id:id_d},
					success:function(data){
						if(data=="true"){
							ajax_trans_page("/SmartCommunity/pc/get_admin_list?page="+page_num); 
						}
						else{
							alert("删除失败！");
						}
					},
					error:function(){
						alert("error");
					}
				});
				  
		        }  	
			
			 		
		}
	</script>
</body>

</html>